package com.spark.market.controller;

import com.spark.market.api.dto.ItemInfo;
import com.spark.market.api.result.ItemListResult;
import com.spark.market.api.utils.ResponseResult;
import com.spark.market.api.utils.ResponseUtil;
import com.spark.market.common.utils.AssertUtils;
import com.spark.market.service.ItemQueryCoreService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;


@RestController
@RequestMapping("item/query")
public class ItemQueryController extends BaseController{
    @Resource
    ItemQueryCoreService itemQueryCoreService;

    @GetMapping(value = "itemDetail/{itemId}")
    public ResponseResult<ItemInfo> getItemDetail(@PathVariable("itemId") Integer itemId) {
        AssertUtils.isNotNull(itemId, "itemId is null");
        return ResponseUtil.createSuccessResult(itemQueryCoreService.getItemDetail(itemId));
    }

    @GetMapping(value = "itemList")
    public ResponseResult<ItemListResult> getItemList(){
        return ResponseUtil.createSuccessResult(itemQueryCoreService.ListItem());
    }

}
